package com.woniu.mgr.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.woniu.mgr.common.Result;
import com.woniu.mgr.controller.form.CoachModifyForm;
import com.woniu.mgr.model.Account;
import com.woniu.mgr.model.Coach;
import com.woniu.mgr.model.Venue;
import com.woniu.mgr.service.AccountService;
import com.woniu.mgr.service.CoachService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 教练特有信息表 前端控制器
 * </p>
 *
 * @author Silas
 * @since 2023-02-15
 */
@RestController
@RequestMapping("/coach")
@Slf4j
@Api(tags = "教练删改查")
public class CoachController {

    @Resource
    private CoachService coachService;
    @Resource
    private AccountService accountService;

    @GetMapping("/coachAll")
    @ApiOperation("平台分页查询教练")
    public Result coachAll(Integer page, Integer size) {
        log.info("执行了分页查询操作 {}{}", page, size);
        IPage<Coach> list = coachService.list(page, size);
        return Result.success(200, "查询成功", list);
    }

    @PutMapping("/coachModify")
    @ApiOperation("平台修改教练")
    public Result coachModify(CoachModifyForm coachModifyForm) {
        log.info("执行了教练修改操作 {}", coachModifyForm);
        coachService.coachModify(coachModifyForm);
        return Result.success(200, "修改成功", null);
    }


    @PostMapping("/coachDelete")
    public Result coachDelete(Integer id) {
        log.info("执行了教练禁用操作 {}", id);
        Coach byId = coachService.getById(id);
        Account account = accountService.getById(byId.getAccountId());
        account.setState("不可用");
        return Result.success(200, "禁用成功", null);
    }

//    @PostMapping("/coachStart")
//    public Result coachStart(Integer id){
//        log.info("执行了教练启用操作 {}", id);
//        Coach byId = coachService.getById(id);
//        Account account = accountService.getById(byId.getAccountId());
//        account.setState("可用");
//        return Result.success(200, "启用成功", null);
//    }


    @GetMapping("query")
    public Result query(String condition, Integer page, Integer size) {
        log.info("查询教练{}{}{}", condition, page, size);
        IPage<Coach> query = coachService.query(condition, page, size);
        return Result.success(200, "查询成功", query);
    }
}

